﻿<!doctype html>
<html>
<!-- InstanceBegin template="/Templates/template1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>会员余额积分</title>
<!-- InstanceEndEditable -->
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/utils.js"></script>
<script type="text/javascript" src="../js/checkLogin.js"></script>
<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery.pager.js"></script>
<link href="../css/style.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/shopSelecterNew.js"></script>
<script type="text/javascript" src="../js/pagination.js"></script>
<script type="text/javascript" src="../js/dataTable.js"></script>
<script type="text/javascript" src="../js/doubleDate2.0.js"></script> 
<script type="text/javascript" src="../js/find.js"></script>
<script type="text/javascript" src="../js/qmsk-1.0.js"></script>
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<script type="text/javascript" >
/**
 * 入口，和服务器的通信从此开始
 */
$(function() {
	refreshInput($(".serWrapper"));
	initShopSelecter();
	$('.doubledate').kuiDate({
		className : 'doubledate',
		isDisabled : "0" // isDisabled为可选参数，“0”表示今日之前不可选，“1”标志今日之前可选
	});
	$('.doubledate1').kuiDate({
		className : 'doubledate1',
		isDisabled : "0" // isDisabled为可选参数，“0”表示今日之前不可选，“1”标志今日之前可选
	});
	initMemberLevel();
	initGoodsTypeSelect();
});

function initMemberLevel(){
	var shopId = $('#shopID').val();
	if(IsNotEmpty(shopId)){
		qmsk.initSelect({
			url : '../memberLevel/find/memberLevelList/0/10?shopId=' + shopId,
			id : 'searchMemberLevel',
			heads : ['ID', 'Name'],
			defaults : {
				key : '请选择会员级别',
				value : ' '
			}
		});
	}
}

function shopSelected(shopId, shopName){
	initMemberLevel();
}


function initGoodsTypeSelect(){
	$("#goodsTypeIsChoosed").removeAttr("checked");
	$("#searchMemberLevel").attr("disabled", "disabled");
	
	$("#goodsTypeIsChoosed").bind("click", function() {
		var checked = $(this).attr("checked");
		if (checked) {
			$("#searchMemberLevel").removeAttr("disabled");
		} else {
			$("#searchMemberLevel").attr("disabled", "disabled");
			$("#searchMemberLevel").empty();
		}
	});
}

/**
 * 为查找做准备，这里主要是生成查询条件对象
 */
function toSearch() {
	$("#memberBalance").empty();
	$("#sum").empty();
	var shopId = $('#shopID').val();
	var mp = $('#mp').val();
	var name = $('#name').val();
	var levelId = $('#searchMemberLevel').val();
	var cardNo = $('#cardNo').val();
	new Pagination({
		url : '../memberBalance/find/balance/opt',
		data : {
			shopId : shopId,
			mp : mp,
			name : name,
			levelId : levelId,
			cardNo : cardNo
		},
		success : printDataToPage,
		pageSize : 10
	});
}



function printDataToPage(message){
	dataTable({
		tbodyId : 'memberBalance',
		heads : ["cardNo", "name", "IDNumber", "mp", "DepositAmount", "IntegralAmount", "CashCouponAmount"],
		rst : message,
		sup : {
			id : "sup",
			template : "共 [index] 条"
		}
	});
	findBalanceSum();
}

/**
 * 累计消费总和
 */
function findBalanceSum(){
	var shopId = $('#shopID').val();
	var mp = $('#mp').val();
	var name = $('#name').val();
	var levelId = $('#searchMemberLevel').val();
	var cardNo = $('#cardNo').val();
/* 	new Pagination({
		url : '../find/sale/goodsTypeInfo/sum',
		data : {
			shopId : shopId,
			mp : mp,
			name : name,
			searchMemberLevel : searchMemberLevel,
			cardNo : cardNo
		},
		success : printDataToPageSum,
		pageSize : 10
	}); */
	var rst = _findInfo("../memberBalance/find/balance/opt/sum",{
		"shopId" : shopId,
		"mp" : mp,
		"name" : name,
		"levelId" : levelId,
		"cardNo" : cardNo
	});
	
	if(IsNotEmpty(rst)){
			var htmlStr = "合计:"
			var htmlGD = "&nbsp&nbsp&nbsp";
			var sum = 0;
			var oldsum = 0;

			var depositAmount = getHtmlInt(getHeadIndexValue(0,rst,'DepositAmount'));
			if(depositAmount > 0){
				sum = sum+depositAmount;
				htmlStr += "预存总计:"+depositAmount;
				oldsum = sum;
			}
			
			var integralAmount = getHtmlInt(getHeadIndexValue(0,rst,'IntegralAmount'));
			if(integralAmount > 0){
				sum = sum+integralAmount;
				if(oldsum < sum && oldsum != 0){
					htmlStr += htmlGD;
				}
				htmlStr += "积分总计:"+integralAmount;
				oldsum = sum;
			}
			
			var cashCouponAmount = getHtmlInt(getHeadIndexValue(0,rst,'CashCouponAmount'));
			if(cashCouponAmount > 0){
				sum = sum+cashCouponAmount;
				if(oldsum < sum && oldsum != 0){
					htmlStr += htmlGD;
				}
				htmlStr += "代金券总计:"+cashCouponAmount;
				oldsum = sum;
			}
		if(sum > 0){
			$("#sum").html(htmlStr);
		}else{
			$("#sum").html("");
		}
	}
}

function downRescouse(){
	$("#memberBalance").empty();
	$("#sum").empty();
	var shopId = $('#shopID').val();
	var mp = $('#mp').val();
	var name = $('#name').val();
	var levelId = $('#searchMemberLevel').val();
	var cardNo = $('#cardNo').val();
	var param={
			shopId : shopId,
			mp : mp,
			name : name,
			levelId : levelId,
			cardNo : cardNo
		}
	window.location.href='../memberBalance/export/csv?'+$.param(param);
	
}


/**
 * 初始化店面选择器
 */
function initShopSelecter() {
	refreshInput($(".serWrapper"));
	$("#shopID").attr("disabled", "disabled");

	$("#shopIsChoosed").bind("click", function() {
		var checked = $(this).attr("checked");
		if (checked) {
			$("#shopID").removeAttr("disabled");
		} else {
			$("#shopID").attr("disabled", "disabled");
			$("#shopID").empty();
		}
	});
}

</script>
</head>

<body>
<div class="container" id="container">
  <div class="container_R fr">
    <div class="place">会员余额积分</div>
    <div class="member_search">
      <p><span>
        <input type="checkbox" id="shopIsChoosed" style="width:auto;height:auto;border:none;">
        店面：</span>
 		<select id="shopID"  class="shopName" onclick="openShopListPanel(this)" style="height: 20px;"></select>
 		<span>手机号：</span><input type="text" id="mp" class="absoluteTxt" >
      	<span>会员姓名：</span><input type="text" id="name" class="absoluteTxt" >
      </p>
      <p>
       <span><input type="checkbox" id="goodsTypeIsChoosed" style="width:auto;height:auto;border:none;">会员级别：</span>
     <select id="searchMemberLevel"  class="shopName"  style="height: 20px;"></select>
      <span>会员卡号：</span>
      <input type="text" id="cardNo" class="absoluteTxt" >
      <input type="button" value="查询" class="btn" onclick="toSearch()">
      </p>
    </div>
    <table width="100%" class="member_list" cellpadding="0" cellspacing="1" border="0" id="memberList">
      <caption>
      <strong>会员余额积分列表 <span id="sup">共0条</span></strong> <a href="javascript:void(0)" onclick="downRescouse()">导出数据</a>
      </caption>
      <thead>
        <tr>
          <th>会员卡号</th>
          <th>会员姓名</th>
          <th>身份证号</th>
          <th>手机</th>
          <th>可用预存</th>
          <th>可用积分</th>
          <th>可用代金券</th>
        </tr>
      </thead>
      <tbody id="memberBalance">
      
      </tbody>
    </table>
     <div id="NoResult"  class="Nothing" style="text-align:center;display: none;">无符合条件的数据！</div>
    <div id="sum" style="float: left;"></div>
    <div id="pager" class="pager"></div>
  </div>
  <div class="fc"></div>
</div>
<!-- InstanceEndEditable --> 
<script type="text/javascript" src="../js/header.js"></script> 
<script type="text/javascript" src="../js/left.js"></script> 
<script type="text/javascript" src="../js/footer.js"></script> 
<script type="text/javascript">
clearThis("absoluteTxt");
</script>
</body>
<!-- InstanceEnd -->
</html>
